/*
*  Copyright 2019-2020 Zheng Jie
*
*  Licensed under the Apache License, Version 2.0 (the "License");
*  you may not use this file except in compliance with the License.
*  You may obtain a copy of the License at
*
*  http://www.apache.org/licenses/LICENSE-2.0
*
*  Unless required by applicable law or agreed to in writing, software
*  distributed under the License is distributed on an "AS IS" BASIS,
*  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*  See the License for the specific language governing permissions and
*  limitations under the License.
*/
package com.yuecai.modules.yc_goods_enshrine_snapshoot;

import com.yuecai.modules.yc_goods_enshrine_snapshoot.domain.YcGoodsEnshrineSnapshoot;
import com.yuecai.modules.yc_goods_enshrine_snapshoot.service.YcGoodsEnshrineSnapshootService;
import com.yuecai.modules.yc_goods_enshrine_snapshoot.service.dto.YcGoodsEnshrineSnapshootQueryCriteria;
import com.yuecai.utils.SecurityUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.data.domain.Pageable;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
* @website https://el-admin.vip
* @author dm
* @date 2020-07-03
**/
@RestController
@RequiredArgsConstructor
@Api(tags = "yc_goods_enshrine_snapshoot管理")
@RequestMapping("/api/ycGoodsEnshrineSnapshoot")
public class YcGoodsEnshrineSnapshootController {

    private final YcGoodsEnshrineSnapshootService ycGoodsEnshrineSnapshootService;


    @GetMapping
    public ResponseEntity<Object> query(YcGoodsEnshrineSnapshootQueryCriteria criteria, Pageable pageable){
        String currentUsername = SecurityUtils.getCurrentUsername();
        criteria.setUserId(Long.valueOf(currentUsername));
        return new ResponseEntity<>(ycGoodsEnshrineSnapshootService.queryAll(criteria,pageable),HttpStatus.OK);
    }
    @GetMapping("/number")
    public ResponseEntity<Object> finCount(YcGoodsEnshrineSnapshootQueryCriteria criteria, Pageable pageable){
        String currentUsername = SecurityUtils.getCurrentUsername();
        criteria.setUserId(Long.valueOf(currentUsername));
        return new ResponseEntity<>(ycGoodsEnshrineSnapshootService.finCount(criteria,pageable),HttpStatus.OK);
    }

    @PostMapping
    public ResponseEntity<Object> create(@Validated @RequestBody YcGoodsEnshrineSnapshoot resources){
        String currentUsername = SecurityUtils.getCurrentUsername();
        Long aLong = Long.valueOf(currentUsername);
        resources.setUserId(aLong);
        return new ResponseEntity<>(ycGoodsEnshrineSnapshootService.create(resources),HttpStatus.OK);
    }


    /**
     * 查看是否收藏
     * @param goodId
     * @return
     */
    @PostMapping("/checkout")
    public ResponseEntity<Boolean> checkOut(@PathVariable Long goodId){
        String currentUsername = SecurityUtils.getCurrentUsername();
        Long userId = Long.valueOf(currentUsername);

        return ResponseEntity.ok(ycGoodsEnshrineSnapshootService.checkOut(userId,goodId));
    }


    @ApiOperation("删除yc_goods_enshrine_snapshoot")
    @DeleteMapping
    public ResponseEntity<Object> delete(@RequestBody Long[] ids) {
        ycGoodsEnshrineSnapshootService.deleteAll(ids);
        return new ResponseEntity<>(HttpStatus.OK);
    }
}